<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
<!-- qopenglvertexarrayobject.cpp -->
  <title>QOpenGLVertexArrayObject Class | Qt GUI 5.14.2</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.14</a></td><td ><a href="qtgui-index.html">Qt GUI</a></td><td ><a href="qtgui-module.html">C++ Classes</a></td><td >QOpenGLVertexArrayObject</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtgui-index.html">Qt 5.14.2 Reference Documentation</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#public-types">Public Types</a></li>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QOpenGLVertexArrayObject Class</h1>
<!-- $$$QOpenGLVertexArrayObject-brief -->
<p>The QOpenGLVertexArrayObject class wraps an OpenGL Vertex Array Object. <a href="#details">More...</a></p>
<!-- @@@QOpenGLVertexArrayObject -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QOpenGLVertexArrayObject&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += gui</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Since:</td><td class="memItemRight bottomAlign"> Qt 5.1</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherits:</td><td class="memItemRight bottomAlign"> <a href="../qtcore/qobject.html">QObject</a></td></tr></table></div><p>This class was introduced in Qt 5.1.</p>
<ul>
<li><a href="qopenglvertexarrayobject-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="public-types"></a>
<h2 id="public-types">Public Types</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> class </td><td class="memItemRight bottomAlign"><b><a href="qopenglvertexarrayobject-binder.html">Binder</a></b></td></tr>
</table></div>
<a name="public-functions"></a>
<h2 id="public-functions">Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qopenglvertexarrayobject.html#QOpenGLVertexArrayObject">QOpenGLVertexArrayObject</a></b>(QObject *<i>parent</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual </td><td class="memItemRight bottomAlign"><b><a href="qopenglvertexarrayobject.html#dtor.QOpenGLVertexArrayObject">~QOpenGLVertexArrayObject</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qopenglvertexarrayobject.html#bind">bind</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qopenglvertexarrayobject.html#create">create</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qopenglvertexarrayobject.html#destroy">destroy</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qopenglvertexarrayobject.html#isCreated">isCreated</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> GLuint </td><td class="memItemRight bottomAlign"><b><a href="qopenglvertexarrayobject.html#objectId">objectId</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qopenglvertexarrayobject.html#release">release</a></b>()</td></tr>
</table></div>
<a name="details"></a>
<!-- $$$QOpenGLVertexArrayObject-description -->
<div class="descr">
<h2 id="details">Detailed Description</h2>
<p>A Vertex Array Object (VAO) is an OpenGL container object that encapsulates the state needed to specify per-vertex attribute data to the OpenGL pipeline. To put it another way, a VAO remembers the states of buffer objects (see <a href="qopenglbuffer.html">QOpenGLBuffer</a>) and their associated state (e.g&#x2e; vertex attribute divisors). This allows a very easy and efficient method of switching between OpenGL buffer states for rendering different &quot;objects&quot; in a scene. The QOpenGLVertexArrayObject class is a thin wrapper around an OpenGL VAO.</p>
<p>For the desktop, VAOs are supported as a core feature in OpenGL 3.0 or newer and by the GL_ARB_vertex_array_object for older versions. On OpenGL ES 2, VAOs are provided by the optional GL_OES_vertex_array_object extension. You can check the version of OpenGL with QOpenGLContext::surfaceFormat() and check for the presence of extensions with <a href="qopenglcontext.html#hasExtension">QOpenGLContext::hasExtension</a>().</p>
<p>As with the other Qt OpenGL classes, QOpenGLVertexArrayObject has a <a href="qopenglvertexarrayobject.html#create">create</a>() function to create the underlying OpenGL object. This is to allow the developer to ensure that there is a valid current OpenGL context at the time.</p>
<p>Once you have successfully created a VAO the typical usage pattern is:</p>
<ul>
<li>In scene initialization function, for each visual object:<ul>
<li>Bind the VAO</li>
<li>Set vertex data state for this visual object (vertices, normals, texture coordinates etc.)</li>
<li>Unbind (<a href="qopenglvertexarrayobject.html#release">release</a>()) the VAO</li>
</ul>
</li>
<li>In render function, for each visual object:<ul>
<li>Bind the VAO (and shader program if needed)</li>
<li>Call a glDraw*() function</li>
<li>Unbind (<a href="qopenglvertexarrayobject.html#release">release</a>()) the VAO</li>
</ul>
</li>
</ul>
<p>The act of binding the VAO in the render function has the effect of restoring all of the vertex data state setup in the initialization phase. In this way we can set a great deal of state when setting up a VAO and efficiently switch between state sets of objects to be rendered. Using VAOs also allows the OpenGL driver to amortise the validation checks of the vertex data.</p>
<p><b>Note: </b>Vertex Array Objects, like all other OpenGL container objects, are specific to the context for which they were created and cannot be shared amongst a context group.</p></div>
<p><b>See also </b><a href="qopenglvertexarrayobject-binder.html">QOpenGLVertexArrayObject::Binder</a> and <a href="qopenglbuffer.html">QOpenGLBuffer</a>.</p>
<!-- @@@QOpenGLVertexArrayObject -->
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QOpenGLVertexArrayObject[overload1]$$$QOpenGLVertexArrayObjectQObject* -->
<h3 class="fn" id="QOpenGLVertexArrayObject"><a name="QOpenGLVertexArrayObject"></a>QOpenGLVertexArrayObject::<span class="name">QOpenGLVertexArrayObject</span>(<span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> *<i>parent</i> = nullptr)</h3>
<p>Creates a QOpenGLVertexArrayObject with the given <i>parent</i>. You must call <a href="qopenglvertexarrayobject.html#create">create</a>() with a valid OpenGL context before using.</p>
<!-- @@@QOpenGLVertexArrayObject -->
<!-- $$$~QOpenGLVertexArrayObject[overload1]$$$~QOpenGLVertexArrayObject -->
<h3 class="fn" id="dtor.QOpenGLVertexArrayObject"><a name="dtor.QOpenGLVertexArrayObject"></a><code>[virtual] </code>QOpenGLVertexArrayObject::<span class="name">~QOpenGLVertexArrayObject</span>()</h3>
<p>Destroys the <a href="qopenglvertexarrayobject.html">QOpenGLVertexArrayObject</a> and the underlying OpenGL resource.</p>
<!-- @@@~QOpenGLVertexArrayObject -->
<!-- $$$bind[overload1]$$$bind -->
<h3 class="fn" id="bind"><a name="bind"></a><span class="type">void</span> QOpenGLVertexArrayObject::<span class="name">bind</span>()</h3>
<p>Binds this vertex array object to the OpenGL binding point. From this point on and until <a href="qopenglvertexarrayobject.html#release">release</a>() is called or another vertex array object is bound, any modifications made to vertex data state are stored inside this vertex array object.</p>
<p>If another vertex array object is then bound you can later restore the set of state associated with this object by calling bind() on this object once again. This allows efficient changes between vertex data states in rendering functions.</p>
<!-- @@@bind -->
<!-- $$$create[overload1]$$$create -->
<h3 class="fn" id="create"><a name="create"></a><span class="type">bool</span> QOpenGLVertexArrayObject::<span class="name">create</span>()</h3>
<p>Creates the underlying OpenGL vertex array object. There must be a valid OpenGL context that supports vertex array objects current for this function to succeed.</p>
<p>Returns <code>true</code> if the OpenGL vertex array object was successfully created.</p>
<p>When the return value is <code>false</code>, vertex array object support is not available. This is not an error: on systems with OpenGL 2.x or OpenGL ES 2.0 vertex array objects may not be supported. The application is free to continue execution in this case, but it then has to be prepared to operate in a VAO-less manner too. This means that instead of merely calling <a href="qopenglvertexarrayobject.html#bind">bind</a>(), the value of <a href="qopenglvertexarrayobject.html#isCreated">isCreated</a>() must be checked and the vertex arrays has to be initialized in the traditional way when there is no vertex array object present.</p>
<p><b>See also </b><a href="qopenglvertexarrayobject.html#isCreated">isCreated</a>().</p>
<!-- @@@create -->
<!-- $$$destroy[overload1]$$$destroy -->
<h3 class="fn" id="destroy"><a name="destroy"></a><span class="type">void</span> QOpenGLVertexArrayObject::<span class="name">destroy</span>()</h3>
<p>Destroys the underlying OpenGL vertex array object. There must be a valid OpenGL context that supports vertex array objects current for this function to succeed.</p>
<!-- @@@destroy -->
<!-- $$$isCreated[overload1]$$$isCreated -->
<h3 class="fn" id="isCreated"><a name="isCreated"></a><span class="type">bool</span> QOpenGLVertexArrayObject::<span class="name">isCreated</span>() const</h3>
<p>Returns <code>true</code> is the underlying OpenGL vertex array object has been created. If this returns <code>true</code> and the associated OpenGL context is current, then you are able to <a href="qopenglvertexarrayobject.html#bind">bind</a>() this object.</p>
<!-- @@@isCreated -->
<!-- $$$objectId[overload1]$$$objectId -->
<h3 class="fn" id="objectId"><a name="objectId"></a><span class="type">GLuint</span> QOpenGLVertexArrayObject::<span class="name">objectId</span>() const</h3>
<p>Returns the id of the underlying OpenGL vertex array object.</p>
<!-- @@@objectId -->
<!-- $$$release[overload1]$$$release -->
<h3 class="fn" id="release"><a name="release"></a><span class="type">void</span> QOpenGLVertexArrayObject::<span class="name">release</span>()</h3>
<p>Unbinds this vertex array object by binding the default vertex array object (id = 0).</p>
<!-- @@@release -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2020 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
